package com.jln.demo.fragment;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.flyco.tablayout.SlidingTabLayout;
import com.jln.demo.R;
import com.jln.demo.adapter.HomeAdapter;
import com.jln.demo.api.Api;
import com.jln.demo.api.ApiConfig;
import com.jln.demo.api.TtitCallback;

import java.util.ArrayList;
import java.util.HashMap;

public class HomeFragment extends BaseFragment {
    private final ArrayList<Fragment> mFragments = new ArrayList<>();
    private String[] mTitles = {"Vlog", "游记"};
    private ViewPager viewPager;
    private SlidingTabLayout slidingTabLayout;

    public HomeFragment() {
    }

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        return fragment;
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        viewPager = mRootView.findViewById(R.id.fixedViewPager);
        slidingTabLayout = mRootView.findViewById(R.id.slidingTabLayout);
    }

    @Override
    protected void initData() {
        getVideoCategoryList();
    }

    private void getVideoCategoryList() {
        //todo 分类
        for (int i = 0; i < mTitles.length; i++) {
            mFragments.add(VideoFragment.newInstance(1));
        }
        viewPager.setOffscreenPageLimit(mFragments.size());
        viewPager.setAdapter(new HomeAdapter(getFragmentManager(), mTitles, mFragments));
        slidingTabLayout.setViewPager(viewPager);


        if (false) {
            HashMap<String, Object> params = new HashMap<>();
            Api.config(ApiConfig.VIDEO_CATEGORY_LIST, params).getRequest(getActivity(), new TtitCallback() {
                @Override
                public void onSuccess(final String res) {
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                        }
                    });
                }

                @Override
                public void onFailure(Exception e) {
                }
            });
        }

    }
}
